package org.example.scoresystem_backen.config;

import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.type.TypeHandlerRegistry;
import org.example.scoresystem_backen.entity.Admin;
import org.example.scoresystem_backen.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import jakarta.annotation.PostConstruct;

/**
 * MyBatis配置类
 * 用于注册自定义类型处理器
 */
@Configuration
public class MyBatisConfig {

    @Autowired
    private SqlSessionFactory sqlSessionFactory;

    /**
     * 注册自定义类型处理器
     */
    @PostConstruct
    public void registerTypeHandlers() {
        TypeHandlerRegistry typeHandlerRegistry = sqlSessionFactory.getConfiguration().getTypeHandlerRegistry();
        
        // 注册Admin.Role类型处理器
        typeHandlerRegistry.register(Admin.Role.class, AdminRoleTypeHandler.class);
        
        // 注册Student.Role类型处理器
        typeHandlerRegistry.register(Student.Role.class, StudentRoleTypeHandler.class);
    }
}
